package day5.Exer;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;


public class HashTabletest {
    public static void main(String[] args) {
        Map<Integer,Integer> a=new HashMap<>();
        Map<Integer,Integer>b=new Hashtable<>();
        long start1=System.nanoTime();
        for(int i=0;i<100000; a.put((int)(Math.random()*1000000),(int)(Math.random()*1000000)),i++);
        long end1=System.nanoTime();
        long time1=end1-start1;
        long start2=System.nanoTime();
        for(int i=0;i<100000; b.put((int)(Math.random()*1000000),(int)(Math.random()*1000000)),i++);
        long end2=System.nanoTime();
        long time2=end2-start2;
        System.out.println("添加1000000个数"+"\n"+"HashMap用时"+time1+"纳秒。"+"\n"+"Hashtable用时"+time2+"纳秒。");
        long start3=System.nanoTime();
        for(int i=0;i<100; a.remove((int)(Math.random()*1000000)),i++);
        long end3=System.nanoTime();
        long time3=end3-start3;
        long start4=System.nanoTime();
        for(int i=0;i<100000; b.remove((int)(Math.random()*1000000)),i++);
        long end4=System.nanoTime();
        long time4=end4-start4;
        System.out.println("删除100个数"+"\n"+"HashMap用时"+time3+"纳秒。"+"\n"+"Hashtable用时"+time4+"纳秒。");
    }
}
